import Vue from 'vue'
import Vuex from 'vuex'
import {getimg,getlist,getdata} from '../api/index'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    img:[],
    list:[],
    datas:[],
    add:[],
  },
  mutations: {
    // 轮播图
    SET_IMG(state,payload){
      state.img=payload
      // console.log(payload)
    },
    // 列表
    SET_LIST(state,payload){
      state.list=payload
      // console.log(payload)
    },
    // 地址栏列表
    SET_DATA(state,payload){
      state.datas=payload
      console.log(payload)
    },
    // 添加首页
    SET_ADD(state,payload){
      state.add=payload
      // console.log(payload)
    },
    // 添加新地址
    SET_ADDRESS(state,payload){
      // let obj={
      //   ...payload,
      //   id:state.datas.length+1
      // }
      // state.datas=[...state.datas].push(obj)
      // console.log(payload)
      state.datas.push({
        ...payload,
        id:state.datas.length+1
      })
      console.log(state.datas)
    },
  },
  actions: {
    async GET_IMG({commit}){
         const resp=await getimg()
         commit('SET_IMG',resp.data.data)
    },
    async GET_LIST({commit}){
      const resp=await getlist()
      commit('SET_LIST',resp.data.data)
 },
 async GET_DATA({commit}){
  const resp=await getdata()
  commit('SET_DATA',resp.data.data)
},
  },
  modules: {
  }
})
